const express = require("express")
const app = express();
const cors = require('cors')
app.use(cors())

/**
 * @name 获取所有抽奖物品
 * @returns status 是否成功 200-成功 0-失败
 * @return message
 * @returns data 返回数据 object[]
 */
app.get("/api/get_lottery_goods", (req, res) => {
  res.send({
    status: 200,
    message: "success",
    data: [
      {
        lottery_name: "物品1",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "1"
      },
      {
        lottery_name: "物品2",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "2"
      },
      {
        lottery_name: "物品3",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "3"
      },
      {
        lottery_name: "物品4",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "4"
      },
      {
        lottery_name: "物品5",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "5"
      },
      {
        lottery_name: "物品6",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "6"
      },
      {
        lottery_name: "物品7",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "7"
      },
      {
        lottery_name: "物品8",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "8"
      },
    ]
  })
})

/**
 * @name 获取抽奖结果
 * @returns message
 * @returns data 中奖物品id
*/
app.get("/api/get_lottery_result", (req, res) => {
  res.send({
    status: 200,
    message: "success",
    data: "1"
  })
})

/**
 * @name 获取当前消耗品数以及每次抽奖消耗数量
 * @returns consumables_count 消耗品总数
 * @returns consume_count 每次消耗的数量
*/

app.get("/api/get_consumables_info", (req, res) => {
  res.send({
    status: 200,
    message: "success",
    data: {
      consumables_count: 1000,
      consume_count: 200,
    }
  })
})

/**
 * @name 获取抽奖池设置
 * @returns status 是否成功 200-成功 0-失败
 * @return message
 * @returns data 返回数据 object[]
 */

 app.get("/api/get_all_lottery_goods", (req, res) => {
  res.send({
    status: 200,
    message: "success",
    data: [
      {
        lottery_name: "物品1",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "1",
        lottery_probability: 50
      },
      {
        lottery_name: "物品2",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "2",
        lottery_probability: 5
      },
      {
        lottery_name: "物品3",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "3",
        lottery_probability: 3
      },
      {
        lottery_name: "物品4",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "4",
        lottery_probability: 15
      },
      {
        lottery_name: "物品5",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "5",
        lottery_probability: 5
      },
      {
        lottery_name: "物品6",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "6",
        lottery_probability: 46
      },
      {
        lottery_name: "物品7",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "7",
        lottery_probability: 6
      },
      {
        lottery_name: "物品8",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "8",
        lottery_probability: 9
      },
      {
        lottery_name: "物品5",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "9",
        lottery_probability: 44
      },
      {
        lottery_name: "物品6",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "10",
        lottery_probability: 18
      },
      {
        lottery_name: "物品7",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "11",
        lottery_probability: 12
      },
      {
        lottery_name: "物品8",
        image_url: "http://152.136.162.68:8000/images/cup.webp",
        lottery_id: "12",
        lottery_probability: 36
      }
    ]
  })
 })

 /**
 * @name 获取抽奖池
 * @returns status 是否成功 200-成功 0-失败
 * @return message
 * @returns data 返回数据 object{}
 */
app.get("/api/get_lottery_goods_settings", (req, res) => {
  res.send({
    status: 200,
    message: "success",
    data: {
      gift_list: ["1", "2", "3", "4", "5", "7", "9", "11"],
      gift_count: 2000,
      gift_used_count: 200
    }
  })
})

app.listen("3030", () => {
  console.log("server is running")
})
